<div class="container" style="width: 100%">
	<form id="searchForm" class="form-horizontal" method="post">
<#list columnDatas as item>
<#if item_index==0 ><#assign dataCount=0>
		<div class="row">
<#elseif dataCount%2==0 && dataCount gt 0>
		<div class="row">
</#if>
		<#if item.queryColumn>
			<div class="control-group span12">
				<label class="control-label">${item.columnComment}：</label>
				<div class="controls">
				<#if item.dataType=='Date'>
					<input type="text" class="calendar calendar-time" name="querySectionMap['${item.domainPropertyName}Begin']"><span> - </span><input
						type="text" class=" calendar calendar-time"name="querySectionMap['${item.domainPropertyName}End']">
				<#else>
					<input type="text" class="control-text" name="${item.domainPropertyName}">
				</#if>
				</div>
			</div>
			<#assign dataCount=dataCount+1>
		</#if>
<#if dataCount gt 0>
<#if !item_has_next || dataCount%2==0>
		</div>
</#if>
</#if>
</#list>

<#list columnDatas as item>
<#if item_index==0> <#assign dataCount=0>
		<div class="hide">
<#elseif dataCount%20==0 && dataCount gt 0>
		<div class="hide">
</#if>
		<#if !item.queryColumn>
			<div class="control-group span12">
				<label class="control-label">${item.columnComment}：</label>
				<div class="controls">
				<#if item.dataType=='Date'>
					<input type="text" class="calendar calendar-time" name="querySectionMap['${item.domainPropertyName}Begin']"><span> - </span><input
						type="text" class=" calendar calendar-time"name="querySectionMap['${item.domainPropertyName}End']">
				<#else>
					<input type="text" class="control-text" name="${item.domainPropertyName}">
				</#if>
				</div>
			</div>
			<#assign dataCount=dataCount+1>
		</#if>
<#if dataCount gt 0>
<#if !item_has_next || dataCount%20==0>
		</div>
</#if>
</#if>
</#list>

		<div class="row">
			<div class="control-group span15">
				<div class="form-actions offset10">
					<button type="submit" id="btnSearch" class="button button-primary"
						id="btnSave">搜索</button>
					<button type="reset" class="button button-primary">重置</button>
				</div>
			</div>
		</div>
	</form>
	
	<div class="search-grid-container">
		<div id="grid"></div>
	</div>
</div>

<script type="text/javascript">
	BUI
			.use(
					[ 'common/search', 'common/page' ],
					function(Search) {
								editing = new BUI.Grid.Plugins.DialogEditing({
									contentId : 'content', //设置隐藏的Dialog内容
									autoSave : true, //添加数据或者修改数据时，自动保存
									triggerCls : 'btn-edit'
								}),
								columns = [
										<#list columnDatas as item>
										<#if item.listColumn>
										{
											title : '${item.columnComment}',
											dataIndex : '${item.domainPropertyName}',
											<#if item.keyColumn>
											renderer : function(v) {
												return Search
														.createLink({
															id : 'detail_' + v,
															title : '查看${codeName}信息',
															text : v,
															href : 'query${className}DetailPage.do?opType=view&rescId='
																	+ v
														});
											},
											</#if>
											<#if item.dataType="Date">
											renderer : BUI.Grid.Format.datetimeRenderer,
											</#if>
											width : 100
										}<#if item_has_next>,</#if>
										</#if>
										</#list>
										{
											title : '操作',
											dataIndex : '',
											width : 150,
											renderer : function(value, obj) {
												var editStr= '<span class="grid-command btn-edit" title="编辑${codeName}信息">编辑</span>', 
												delStr = '<span class="grid-command btn-del" title="删除${codeName}信息">删除</span>';
												return editStr + delStr;
											}
										} ],
								store = Search
										.createStore(
												'asynQuery${className}List.do',
												{
													autoSync : true,
													pageSize : 10,
													proxy : {
														save : { //也可以是一个字符串，那么增删改，都会往那么路径提交数据，同时附加参数saveType
															addUrl : 'asynSave${className}.do',
															updateUrl : 'asynSave${className}.do',
															removeUrl : 'asynSave${className}.do'
														},
														method : 'POST'
													}
												}),
								gridCfg = Search
										.createGridCfg(
												columns,
												{
													forceFit : true,
													tbar : {
														items : [
																{
																	text : '<i class="icon-plus"></i>新建',
																	btnCls : 'button button-small',
																	handler : addFunction
																},
																{
																	text : '<i class="icon-remove"></i>删除',
																	btnCls : 'button button-small',
																	handler : delFunction
																} ]
													},
													plugins : [
															editing,
															BUI.Grid.Plugins.CheckSelection,
															BUI.Grid.Plugins.AutoFit ]
												// 插件形式引入多选表格
												});

						var search = new Search({
							store : store,
							gridCfg : gridCfg
						}), grid = search.get('grid');

						//新增操作
						function addFunction() {
							var newData = {
								isNew : true
							}; //标志是新增加的记录
							editing.add(newData, 'name'); //添加记录后，直接编辑
						}
						//删除操作
						function delFunction() {
							var selections = grid.getSelection();
							delItems(selections);
						}
						function delItems(items) {
							var ids = [];
							BUI.each(items, function(item) {
								ids.push(item.rescId);
							});

							if (ids.length) {
								BUI.Message.Confirm('确认要删除选中的记录么？', function() {
									$.ajax({
										url : 'asynDelete${className}.do',
										type : 'post',
										dataType : 'json',
										data : {
											rescIds : JSON.stringify(ids)
										},
										success : function(data) {
											if (data.success) { //删除成功
												search.load();
											} else { //删除失败
												BUI.Message.Alert('删除失败！');
											}
										}
									});
								}, 'question');
							}
						}

						//监听事件，删除一条记录
						grid.on('cellclick', function(ev) {
							var sender = $(ev.domTarget); //点击的Dom
							if (sender.hasClass('btn-del')) {
								var record = ev.record;
								delItems([ record ]);
							}
						});
					});
</script>

<div id="content" class="hide">
	<form id="J_Form" class="form-horizontal" action="asynSave${className}.do" method="post">
<#list columnDatas as item>
<#if item_index==0 ><#assign dataCount=0>
	<div class="row">
<#elseif dataCount%2==0 && dataCount gt 0>
	<div class="row">
</#if>
		<#if item.showDetail>
		<div class="control-group span8">
			<label class="control-label"><s>*</s>${item.columnComment}：</label>
			<div class="controls">
			<#if item.dataType=='Date'>
				<input name="${item.domainPropertyName}" type="text" <#if !item.canUpdate>readonly="readonly"</#if>
				<#if !item.nullAble>data-rules="{required:true}"</#if>
						class="calendar calendar-time" value="$!{sysResc.createdTime}">
			<#else>
				<input name="${item.domainPropertyName}" type="text" <#if !item.canUpdate>readonly="readonly"</#if>
				<#if !item.nullAble>data-rules="{required:true}"</#if>
				 		class="input-normal control-text"
						value="${item.domainPropertyName}">
			</#if>
			</div>
		</div>
		<#assign dataCount=dataCount+1>
		</#if>
<#if dataCount gt 0>
<#if !item_has_next || dataCount%2==0>
	</div>
</#if>
</#if>
</#list>

<#list columnDatas as item>
<#if item_index==0> <#assign dataCount=0>
	<div class="hide">
<#elseif dataCount%20==0 && dataCount gt 0>
	<div class="hide">
</#if>
		<#if !item.showDetail>
		<div class="control-group span8">
			<label class="control-label"><s>*</s>${item.columnComment}：</label>
			<div class="controls">
			<#if item.dataType=='Date'>
				<input name="${item.domainPropertyName}" type="text" <#if !item.canUpdate>readonly="readonly"</#if>
				<#if !item.nullAble>data-rules="{required:true}"</#if>
						class="calendar calendar-time" value="$!{sysResc.createdTime}">
			<#else>
				<input name="${item.domainPropertyName}" type="text" <#if !item.canUpdate>readonly="readonly"</#if>
				<#if !item.nullAble>data-rules="{required:true}"</#if>
				 		class="input-normal control-text"
						value="${item.domainPropertyName}">
			</#if>
			</div>
		</div>
			<#assign dataCount=dataCount+1>
		</#if>
<#if dataCount gt 0>
<#if !item_has_next || dataCount%20==0>
	</div>
</#if>
</#if>
</#list>
	</form>
</div>